package com.hunt.controller;

import com.hunt.dao.TransactionCalendarMapper;
import com.hunt.model.app.FncWarningResults;
import com.hunt.model.entity.*;
import com.hunt.service.ExChangeLogService;
import com.hunt.service.LongHuService;
import com.hunt.util.LongHuFieldMap;
import com.hunt.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

@Api(value = "龙虎榜获取")
@Controller
@RequestMapping(path = "/LongHu")
public class LonghuController extends BaseController {

    @Autowired
    private LongHuService longHuService;
    @Autowired
    private TransactionCalendarMapper transactionCalendarMapper;
    @ApiOperation(value = "查询", httpMethod = "GET", produces = "application/json", response = Result.class)
    @ResponseBody
    @RequestMapping(value = "getinfo", method = RequestMethod.GET)
    public Result getinfo(@RequestParam(value = "date",defaultValue = "0") String date, @RequestParam(value = "orderfield",defaultValue = "0",required = false)@ApiParam(value ="0是priceChangeRatio,1是closingPrice,2是turnoverRate,3是totalTurnover,4是totalMarketTurnover,5是netPurchaseAmount,6是buyAmount,7是sellAmount") int orderfield, @RequestParam(value = "sort", defaultValue = "1",required = false)@ApiParam(value = "0是升序,1是降序") int sort) {
        Date todaydate=new Date();
        SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyyMMdd");
        String todaydatestr=simpleDateFormat.format(todaydate);
        //0代表最新的
        if ("0".equals(date)) {
            date=todaydatestr;
            LongHuPoResult lpr=longHuService.getlatestpo(date,orderfield,sort);
            return Result.success(lpr);
        }
        else {
            LongHuPoResult lpr=longHuService.getpo(date,orderfield,sort);
            return Result.success(lpr);
        }
    }
    @ApiOperation(value = "查询单独股票", httpMethod = "GET", produces = "application/json", response = Result.class)
    @ResponseBody
    @RequestMapping(value = "getinfodetail", method = RequestMethod.GET)
    public Result getinfodetail(@RequestParam(value = "date",defaultValue = "0") String date,@RequestParam(value = "code") String code,@RequestParam(value = "isThreeDay",defaultValue = "0") String isThreeDay,@RequestParam(value = "listingReason",defaultValue = "0") String listingReason) throws ParseException {
        //0代表最新的
        if ("0".equals(date)) {
            LongHuDetail ld=longHuService.getlatestpodetail(date,code,isThreeDay,listingReason);
            return Result.success(ld);
        }
        else {
            LongHuDetail ld=longHuService.getpodetail(date,code,isThreeDay,listingReason);
            return Result.success(ld);
        }
    }
}